<?php
$entity_count_first = $pages->getEntityCount() ? $pages->getPerPage() * ($page->getPageNumber() - 1) + 1 : 0;
$entity_count_last = ($pages->getEntityCount() < $entity_count_now = $pages->getPerPage() * $page->getPageNumber()) ? $pages->getEntityCount() : $entity_count_now;
$node_nav_result = __('Showing %1$d - %2$d of %3$d', array($entity_count_first, $entity_count_last, $pages->getEntityCount()));
?>
<div class="nodesBreadcrumb">
  <?php echo $this->helper('XiggBreadCrumb', $CONFIG);?><a href="<?php echo Sabai_URL::get('/tag');?>"><?php _e('Tags');?></a> &#8250; <?php _h(sprintf(_('Tag: %s'), $tag->getLabel()));?>
</div>
<div class="nodesHead clearfix">
  <ul>
<?php if ($CONFIG->get('useUpcomingFeature')):?>
    <li class="active"><?php _e('Popular news');?></li>
    <li>
      <a href="<?php echo Sabai_URL::get($route .'/upcoming');?>" title="<?php _e('Upcoming news');?>"><?php _h(sprintf(_('Upcoming news (%d)'), $upcoming_count));?></a>
    </li>
<?php else:?>
    <li class="active"><?php _e('News list');?></li>
<?php endif;?>
<?php if ($USER->isInRole(array(XIGG_ROLE_ADMIN, XIGG_ROLE_EDITOR, XIGG_ROLE_WRITER, XIGG_ROLE_SUBMITTER))):?>
    <li>
      <a href="<?php echo Sabai_URL::get('/submit');?>" title="<?php _e('Submit news');?>"><?php _e('Submit news');?></a>
    </li>
<?php endif;?>
  </ul>
  <h1 class="categoryTitle"><?php _h(sprintf(_('Tag: %s'), $tag->getLabel()));?></h1>
</div>
<div class="nodesFeed">
  <a href="<?php echo Sabai_URL::get('/rss' . $route);?>"><img src="<?php echo $LAYOUT_URL;?>/images/feed.png" width="16" height="16" alt="RSS feed" title="RSS feed" /></a>
</div>
<div class="nodesSearch">&nbsp;</div>
<table class="nodesNav">
  <tr>
    <td class="nodesNavResults"><?php echo $node_nav_result;?></td>
    <td class="nodesNavSort"><?php _e('Sort by: '); select_to_remote('period', $requested_period, 'xigg-main-shownodesbytag', $sorts, array('base' => $route), _('GO'));?></td>
  </tr>
</table>
<?php if (isset($nodes)): $nodes =& $nodes->with('User'); $nodes =& $nodes->with('LastComment', 'User'); $nodes->rewind();?>
<table class="nodes" cellspacing="0">
  <thead>
    <tr>
      <th class="text"><?php _e('Title');?></th>
      <th><?php _e('Views');?></th>
      <th><?php _e('Votes');?></th>
      <th><?php _e('Replies');?></th>
<?php   if ($CONFIG->get('useUpcomingFeature')):?>
      <th><?php _e('Published');?></th>
<?php   endif;?>
      <th class="text"><?php _e('Last reply');?></th>
    </tr>
  </thead>
  <tbody>
<?php   while ($e =& $nodes->getNext()):
          if ($e->isHidden()):?>
    <tr style="background-color:#eee;">
<?php     else:?>
    <tr>
<?php     endif;?>
      <td class="nodeInfoPoster text">
<?php     $node_user =& $e->get('User'); $node_user->printHTMLImageLink(32, 32);?>
<?php     if (!$e->get('allow_comments')):?><img src="<?php echo $LAYOUT_URL?>/images/tick.gif" alt="" /><?php endif;?>
<?php     if (!isset($category)) $category =& $e->get('Category');?>
<?php     if ($category) printf('<a href="%s">%s</a>: ', Sabai_URL::get('', array('category_id' => $category->getId())), h($category->getLabel()));?>
<?php     unset($category);?>
        <a href="<?php echo Sabai_URL::get('/node/' . $e->getId());?>"><?php _h($e->get('title'));?></a><br />
<?php     printf(_('%s posted <strong>%s</strong>'), $node_user->getHTMLLink(), h($this->helper('XiggAgo', $e->getTimeCreated())));?>
      </td>
      <td><?php echo number_format($e->get('views'));?></td>
      <td><?php echo $e->getVoteCount();?></td>
      <td><?php echo $e->getCommentCount();?></td>
<?php     if ($CONFIG->get('useUpcomingFeature')):?>
      <td><?php if ($e->isPublished()) _h($this->helper('XiggAgo', $e->get('published')));?></td>
<?php     endif;?>
      <td class="nodeInfoPoster text">
<?php     if ($last_comment =& $e->get('LastComment')):?>
<?php       if ($last_user =& $last_comment->get('User')) $last_user->printHTMLImageLink(32, 32);?><a href="<?php echo Sabai_URL::get('/node/' . $e->getId(), array('comment_id' => $last_comment->getId()), 'comment' . $last_comment->getId());?>"><?php _h($last_comment->getLabel());?></a><br />
<?php       printf(_('%s posted <strong>%s</strong>'), $last_user->getHTMLLink(), h($this->helper('XiggAgo', $last_comment->getTimeCreated())));?>
<?php     endif;?>
      </td>
    </tr>
<?php   endwhile; ?>
  </tbody>
</table>
<table class="nodesNav">
  <tr>
    <td class="nodesNavPages"><?php echo $this->helper('PageNavRemote', 'xigg-main-shownodesbytag', $pages, $page->getPageNumber(), array('base' => $route, 'params' => array('period' => $requested_period)));?></td>
  </tr>
</table>
<?php endif;?>